package com.payment.impl;

import java.util.List;

import com.basic.service.contract.IBaseService;
import com.payment.IPaymentBehavior;
import com.translate.entity.Order;
import com.translate.web.param.contract.IPayBehaviorRequestParam;
import com.translate.web.service.IOrderLogService;
import com.translate.web.service.IOrderService;
import com.translate.web.service.IPayManagerService;

/**
 * 普通支付
 * @author opjklu@126.com
 * @param <T>
 */
public class NormalPayByOrder<T> implements IPaymentBehavior{

	private IBaseService<T>[] baseServices;
	
	public NormalPayByOrder(IBaseService<T>[] baseServices) {
		this.baseServices = baseServices;
	}
	
	@Override
	public int pay(IPayBehaviorRequestParam behaviorRequestParam) {

		// 订单状态变为 待确认
		
		// 更新订单状态
		
		IOrderService orderService = (IOrderService) baseServices[0];
		
		Order dataDetail = orderService.getDataDetail(behaviorRequestParam);
		
		if (null == dataDetail) {
            return 3006;
        }
		
		if (0 == dataDetail.getServiceType()) { // 不是作图服务 不允许 在订单列表中支付
			return 3007;
		}
		
		
		orderService.toBeConfirmed(behaviorRequestParam);
		
		// 添加日志
		
		// 添加订单记录
		List<Order> ordersByUserIdAndManagerId = orderService.getOrdersByUserIdAndManagerId(behaviorRequestParam);
				
		IOrderLogService logService = (IOrderLogService) baseServices[2];
		
		return logService.toBeConfirmed(behaviorRequestParam, ordersByUserIdAndManagerId.stream().mapToInt(e->e.getId()).toArray());
		
	}

}
